﻿using System;
using System.Linq;
using System.Windows.Input;
using Microsoft.VisualStudio.TestTools.UITesting;
using Microsoft.VisualStudio.TestTools.UITesting.HtmlControls;
using Microsoft.VisualStudio.TestTools.UITesting.WinControls;

namespace TestExtensions
{
    public static class FluentUIExtensions
    {
        public static TControl SendKeys<TControl>(this TControl @this, string text, ModifierKeys modifierKeys)
            where TControl : UITestControl
        {
            Keyboard.SendKeys(text, modifierKeys);
            return @this;
        }

        public static TControl Click<TControl>(this TControl @this)
            where TControl : UITestControl
        {
            Mouse.Click(@this);
            return @this;
        }

        public static TComboBox SetEditableItem<TComboBox>(this TComboBox @this, string text)
            where TComboBox : WinComboBox
        {
            @this.EditableItem = text;
            return @this;
        }

        public static TBrowserWindow NavigateToUrl<TBrowserWindow>(this TBrowserWindow @this, string url)
            where TBrowserWindow : BrowserWindow
        {
            @this.NavigateToUrl(new Uri(url));
            return @this;
        }

        public static bool InheritsClass<TControl>(this TControl @this, string className)
            where TControl : HtmlControl
        {
            return @this.Class.Split(' ').Contains(className);
        }
    }
}